package com.letian.web.controller.record;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.record.domain.RecordPlace;
import com.letian.record.service.IRecordPlaceService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 记录地址Controller
 * 
 * @author bmz
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/record/place")
public class RecordPlaceController extends BaseController
{
    @Autowired
    private IRecordPlaceService recordPlaceService;

    /**
     * 查询记录地址列表
     */
    @PreAuthorize("@ss.hasPermi('record:place:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordPlace recordPlace)
    {
        startPage();
        List<RecordPlace> list = recordPlaceService.selectRecordPlaceList(recordPlace);
        return getDataTable(list);
    }

    /**
     * 查询记录地址列表
     */
    @PreAuthorize("@ss.hasPermi('record:place:list')")
    @GetMapping("/my/list")
    public TableDataInfo myList(RecordPlace recordPlace)
    {
        startPage();
        recordPlace.setOwner(getUsername());
        List<RecordPlace> list = recordPlaceService.selectRecordPlaceList(recordPlace);
        return getDataTable(list);
    }

    /**
     * 导出记录地址列表
     */
    @PreAuthorize("@ss.hasPermi('record:place:export')")
    @Log(title = "记录地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordPlace recordPlace)
    {
        List<RecordPlace> list = recordPlaceService.selectRecordPlaceList(recordPlace);
        ExcelUtil<RecordPlace> util = new ExcelUtil<RecordPlace>(RecordPlace.class);
        util.exportExcel(response, list, "记录地址数据");
    }

    /**
     * 获取记录地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:place:query')")
    @GetMapping(value = "/{placeId}")
    public AjaxResult getInfo(@PathVariable("placeId") Long placeId)
    {
        return success(recordPlaceService.selectRecordPlaceByPlaceId(placeId));
    }

    /**
     * 新增记录地址
     */
    @PreAuthorize("@ss.hasPermi('record:place:add')")
    @Log(title = "记录地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordPlace recordPlace)
    {
        recordPlace.setOwner(getUsername());
        recordPlace.setCreateBy(getUsername());
        return toAjax(recordPlaceService.insertRecordPlace(recordPlace));
    }

    /**
     * 修改记录地址
     */
    @PreAuthorize("@ss.hasPermi('record:place:edit')")
    @Log(title = "记录地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordPlace recordPlace)
    {
        recordPlace.setUpdateBy(getUsername());
        return toAjax(recordPlaceService.updateRecordPlace(recordPlace));
    }

    /**
     * 删除记录地址
     */
    @PreAuthorize("@ss.hasPermi('record:place:remove')")
    @Log(title = "记录地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{placeIds}")
    public AjaxResult remove(@PathVariable Long[] placeIds)
    {
        return toAjax(recordPlaceService.deleteRecordPlaceByPlaceIds(placeIds));
    }
}
